from pyecharts import options as opts
from pyecharts.charts import Pie

class Pic:
  def __init__(self,data=[],seriesName='',title=''):
    self.data = data
    self.seriesName = seriesName
    self.title = title

  # 简单数据出图
  # 单图
  def draw(self,filename):
    c = (
      Pie()
      .add_dataset(
          source=self.data
      )
      .add(
          series_name=self.seriesName,
          data_pair=[], 
      )
      .set_global_opts(
          title_opts=opts.TitleOpts(title=self.title),
      )
      .render('{}.html'.format(filename))
    )
    
  # 复杂数据
  # 多图
  def draw_series(self,filename):
    c = (
      Pie()
      .add_dataset(
          source=self.data
      )
      .add(
          series_name="最高薪水",
          data_pair=[],
          radius=60,
          center=["25%", "25%"],
          encode={"itemName": "header", "value": "最高薪水"},
      )
      .add(
          series_name="最低薪水",
          data_pair=[],
          radius=60,
          center=["75%", "25%"],
          encode={"itemName": "header", "value": "最低薪水"},
      )
      .add(
          series_name="平均薪水",
          data_pair=[],
          radius=60,
          center=["25%", "75%"],
          encode={"itemName": "header", "value": "平均薪水"},
      )
      .set_global_opts(
          title_opts=opts.TitleOpts(title=self.title, subtitle="数据纯属虚构"),
          legend_opts=opts.LegendOpts(pos_left="30%", pos_top="2%"),
      )
      .render("{}.html".format(filename))
    )